package com.imc.api.templmess.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.imc.api.templmess.pojo.TempMall;
import com.imc.api.templmess.pojo.Token;
import com.imc.api.templmess.service.http.ITempMessService;
import com.imc.api.templmess.service.http.IWXTemplmallService;
import com.imc.api.templmess.utils.WXHttpsUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by tanweiping on 2019/1/8.
 */
@Slf4j
@Transactional
@Service
public class TemplateService
{

    @Autowired
    IWXTemplmallService iwxTemplmallService;


    /*
    * tanweiping  2019/1/8 14:03
    * 方法描述：获取accessToken从redis
    */
    @Cacheable(value = "mpAccessToken#7200#7200",keyGenerator = "keyGenerator")
    public String getAccessToken(Token token){
        return iwxTemplmallService.getAccessToken(
                iwxTemplmallService.beanToMap(token)
        ).getString("access_token");
    }

    public JSONObject messSend(TempMall tempMall){
         return iwxTemplmallService.messAgesSend(tempMall,tempMall.getAccess_token());
    }


}
